package com.elitetyc.eliteim.client.handler.impl;

import com.elitetyc.eliteim.common.constant.Constants;
import com.elitetyc.eliteim.common.handler.impl.BaseMsgHandler;
import com.elitetyc.eliteim.common.model.impl.IMUserInfoImpl;
import com.elitetyc.eliteim.common.proto.RequestProto;
import com.elitetyc.eliteim.common.util.MsgUtil;
import com.elitetyc.eliteim.client.config.IMClientProperties;
import io.netty.channel.ChannelHandlerContext;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author yuanchao.tan
 * @version 1.0
 * @description 获取用户列表
 * @Date 2021/9/17 16:11
 */
@Component
@Slf4j
public class UserListMsgHandlerImpl extends BaseMsgHandler<List<IMUserInfoImpl>> {


    @Autowired
    private IMClientProperties imClientProperties;

    @Override
    public boolean support(int type) {
        return Constants.RequestType.ULIST==type;
    }

    @Override
    public void handleMsg(ChannelHandlerContext ctx, RequestProto.RequestProtocol source, List<IMUserInfoImpl> msg) {
        if (msg.isEmpty()){
            MsgUtil.echoMsg("暂无其他在线用户!");
        }
        for (IMUserInfoImpl imUserInfo : msg) {
            if (imUserInfo.getUserId().equals(imClientProperties.getUserId()))
                continue;
            MsgUtil.echoMsg(imUserInfo.getUserName()+"【"+imUserInfo.getUserId()+"】");
        }
    }
}
